package da;

import java.sql.*;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import java.util.ResourceBundle;

/**
 *
 * @author groep 11
 * @date 2007-2008
 */
public class DatabaseConnection {

    private MysqlConnectionPoolDataSource pool;
    private static DatabaseConnection instance = new DatabaseConnection();
    private ResourceBundle bundle;

    private DatabaseConnection() {
        
            pool = new MysqlConnectionPoolDataSource();
            bundle = ResourceBundle.getBundle("da.dbconsts");
            
            pool.setDatabaseName(bundle.getString("dbname"));
            pool.setServerName(bundle.getString("servername"));
            pool.setUser(bundle.getString("dbuser"));
            pool.setPassword(bundle.getString("dbpassword"));
            
    }

    /**
     * Returns singleton instance of DB connection object
     * @return instance
     */
    public static DatabaseConnection getInstance() {
        return instance;
    }

    /**
     * Returns a SQL-connection with the db
     * @throws java.sql.SQLException
     * @return connection
     */
    public java.sql.Connection getConnection() throws SQLException {
        return pool.getConnection();
    }
}
